/*******************************************************************************
 * Copyright (c) 2009 Ravenhearte Design.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 * 	*	Redistributions of source code must retain the above copyright
 * 		notice, this list of conditions and the following disclaimer.
 * 
 * 	*	Redistributions in binary form must reproduce the above copyright
 * 		notice, this list of conditions and the following disclaimer in the
 * 		documentation and/or other materials provided with the distribution.
 * 
 * 	*	Neither the name of 'Ravenhearte Design' nor the names of its contributors 
 * 		may be used to endorse or promote products derived from this software 
 * 		without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ******************************************************************************/

package org.ravenhearte.gameplay.concepts.locations;

import org.ravenhearte.gameplay.concepts.Location;
import org.ravenhearte.gameplay.objects.architecture.*;

import com.jme.math.Vector3f;

public class Room extends Location {
	private Floor floor;
	private Wall north, south, east, west;

	public Room(String name) {
		this(name, 40, 40, 8);
	}

	public Room(String name, float width, float length, float height) {
		super(name);

		floor = new Floor(name + " Floor", width, length);
		node.attachChild(floor);

		north = new Wall(name + " North Wall", width, height);
		Vector3f location = north.getLocalTranslation();
		location = location.add(Vector3f.UNIT_X.mult(length / 2));
		location = location.add(Vector3f.UNIT_Z.mult(height / 2));
		north.setLocalTranslation(location);
		node.attachChild(north);
		
		south = new Wall(name + " South Wall", width, height);
		location = south.getLocalTranslation();
		location = location.add(Vector3f.UNIT_X.mult(-1).mult(length / 2));
		location = location.add(Vector3f.UNIT_Z.mult(height / 2));
		south.setLocalTranslation(location);
		node.attachChild(south);
		
		east = new Wall(name + " East Wall", length, height);
		location = east.getLocalTranslation();
		location = location.add(Vector3f.UNIT_Y.mult(width / 2));
		location = location.add(Vector3f.UNIT_Z.mult(height / 2));
		east.setLocalTranslation(location);
		node.attachChild(east);
		
		west = new Wall(name + " West Wall", length, height);
		location = west.getLocalTranslation();
		location = location.add(Vector3f.UNIT_Y.mult(-1).mult(width / 2));
		location = location.add(Vector3f.UNIT_Z.mult(height / 2));
		west.setLocalTranslation(location);
		node.attachChild(west);

		north.lookAt(south.getLocalTranslation(), Vector3f.UNIT_Z);
		south.lookAt(north.getLocalTranslation(), Vector3f.UNIT_Z);
		west.lookAt(east.getLocalTranslation(), Vector3f.UNIT_Z);
		east.lookAt(west.getLocalTranslation(), Vector3f.UNIT_Z);

		node.updateWorldData(0);
	}
}
